/*********************************************************************************
 *      Copyright:  (C) 2022 Yang Xiaohan<yangxiaohan@163.com>
 *                  All rights reserved.
 *
 *       Filename:  send_temper.c
 *    Description:  This file 
 *                 
 *        Version:  1.0.0(26/04/22)
 *         Author:  Yang Xiaohan <yangxiaohan@163.com>
 *      ChangeLog:  1, Release initial version on "26/04/22 15:58:58"
 *                 
 ********************************************************************************/

#include <stdio.h>
#include <time.h>
#include <string.h>
#include <stdlib.h>
#include "ds18b20.h"
#include "get_data.h"

#define LEN        64

int get_all_data(char *dev_id,char *time_buf,float *temp,char *sample_buf)
{
	
		 int				rc = -1;
		 int				size = 64;
		
		 //获取时间
		 memset(time_buf,0,LEN);
		 rc = get_time(time_buf,size);
		 if( rc != 0 )
         {
             printf("Get time failure\n");
             return -1;
         }
         //获取温度
		 rc = get_temperature(&(*temp));
		 if(rc != 0)
		 {
			 printf("get temp error.\n");
			 return -1;
		 }
		 //获取设备号
		 memset(dev_id,0,LEN);
		 rc = get_deviceID(dev_id);
		 if(rc != 0)
		 {
			 printf("get id error.\n");
			 return -1;
		 }
		 
		 snprintf(sample_buf,512,"%s|%s|%0.2f℃",dev_id,time_buf,*temp);
		 //printf("buf:%s\n",sample_buf);
		 return 0;
}

int get_time(char *time_buf,int size)
{
		time_t               now;
		struct tm            *info;

		time(&now);
		info = localtime(&now);

		memset(time_buf, 0, size);
		strftime(time_buf, size, "%Y-%m-%d %H:%M:%S",info);

		return 0;
}

int get_deviceID(char *id)
{
	int				sn = 1;

	snprintf(id,LEN,"RPI#%04d",sn);

	return 0;
}
